<?php
class LOGS{
    //general variables
	var $dbErrorMsg = "Failed set/get data from database (Class LOGS): ";

    /**
     * function for getting the logs
     * return : array with all records in log
     */
    function getLogs($orderby='modif', $order='desc'){
        $res = MAIN::returnArray("select `".tblPrefix."logs`.*, users.email
                                  from `".tblPrefix."logs`
                                  LEFT join `".tblPrefix."users`
                                  on logs.user_id = users.id
                                  order by ".$orderby." ".$order);
        return $res;
    }
    /**
     * Function for saving entry into the log
     *
     */
    function setLog($type, $desc, $str1, $str2){
        if(isset($_SESSION[svar])){
            $userId = MAIN::decode($_SESSION[svar]);
        }else{
            $userId = -1;
        }
        $sql = "insert into `".tblPrefix."logs` (`type`, `description`, `field1`, `field2`, `user_id`) values ('".$type."', '".$desc."', '".$str1."', '".$str2."', ".$userId.")";
        return MAIN::executeCommand($sql);
    }
	
	function getUserLogs($userId,$orderby='modif', $order='desc'){
        $res = MAIN::returnArray("select `".tblPrefix."logs`.*, `".tblPrefix."users`.`email`
                                  from `".tblPrefix."logs`
                                  inner join `".tblPrefix."users`
                                  on `".tblPrefix."logs`.`user_id` = `".tblPrefix."users`.`id`
                                  where `".tblPrefix."logs`.`field1`=".$userId."
                                  order by ".$orderby." ".$order);
        return $res;
    }

}
?>